import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

public class MethodQuote {

    /**
     * 实例几种方法引用
     * @param args
     */
    public static void main(String[] args) {

        List<Apple> apples = Arrays.asList(new Apple("青色", 20), new Apple("红色", 5));
        apples.sort((a1, a2) -> a1.getColor().compareTo(a2.getColor()));
        apples.sort(Comparator.comparing(Apple::getColor)); //类非静态方法引用


        Supplier<String> supplier = new Apple("青色", 20)::getColor; //对象方法引用

        Supplier<Apple> supplier2 = Apple::new; //构造方法引用

        Function<String, Integer> supplier4 = Integer::parseInt; //静态方法引用
    }

    public static class Apple {
        private String color;
        private double weight;

        public Apple() {
        }

        public Apple(String color, double weight) {
            this.color = color;
            this.weight = weight;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public double getWeight() {
            return weight;
        }

        public void setWeight(double weight) {
            this.weight = weight;
        }
    }
}
